//
//  TuiChuLoginAlertView.m
//  FactorySale
//
//  Created by 李 on 2020/1/13.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "TuiChuLoginAlertView.h"

@implementation TuiChuLoginAlertView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self configViewsWithFrame:frame];
    }
    
    return self;
    
}
-(void)configViewsWithFrame:(CGRect)frame
{
    self.frame = frame;   

    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT)];
    backView.backgroundColor = [UIColor colorWithHexString:@"#000000"];
    backView.alpha = 0.5;
    [self addSubview:backView];
    
    
    UIView *whiteView = [[UIView alloc]initWithFrame:CGRectMake(38, 270, KWIDTH-38-38, 170)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.cornerRadius = 4;
    [self addSubview:whiteView];
    
    UILabel *titleLab = [[UILabel alloc] init];
           titleLab.text = @"温馨提示";
           titleLab.font =  KFontPingFangSCBold(17);
           titleLab.textAlignment = NSTextAlignmentCenter;
           titleLab.textColor = [UIColor colorWithHexString:@"#333333"];
           titleLab.numberOfLines = 0;
           [whiteView addSubview:titleLab];
           [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
                            make.left.equalTo(whiteView.mas_left).mas_offset(15);
                            make.top.equalTo(whiteView.mas_top).mas_offset(27);
                       make.width.mas_greaterThanOrEqualTo(100);
                       make.height.mas_equalTo(17);

                        }];
    
        UILabel *contentLab = [[UILabel alloc] init];
              contentLab.text = self.contentText;
              contentLab.font =  KFontPingFangSCRegular(13);
              contentLab.textAlignment = NSTextAlignmentLeft;
              contentLab.textColor = [UIColor colorWithHexString:@"#333333"];
              contentLab.numberOfLines = 0;
              [whiteView addSubview:contentLab];
              [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
                               make.left.equalTo(whiteView.mas_left).mas_offset(30);
                               make.top.equalTo(titleLab.mas_bottom).mas_offset(23);
                          make.width.mas_greaterThanOrEqualTo(200);
                          make.height.mas_equalTo(13);

                           }];
    self.contentLab = contentLab;
    
    UIButton *cancleBtn = [UIButton  buttonWithType:(UIButtonTypeCustom)];
       [cancleBtn setTitle:@"取消" forState:(UIControlStateNormal)];
       [cancleBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:(UIControlStateNormal)];
    cancleBtn.titleLabel.font = KFontPingFangSCBold(15);
       [cancleBtn addTarget:self action:@selector(cancleBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [whiteView addSubview:cancleBtn];

       [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
              make.right.equalTo(whiteView.mas_right).mas_offset(-120);
            make.top.equalTo(whiteView.mas_top).mas_offset(123);
                                  make.width.mas_equalTo(50);
                                  make.height.mas_equalTo(20);
       }];
    
   UIButton *sureBtn = [UIButton  buttonWithType:(UIButtonTypeCustom)];
       [sureBtn setTitle:@"确定" forState:(UIControlStateNormal)];
       [sureBtn setTitleColor:[UIColor colorWithHexString:@"#1CAA89"] forState:(UIControlStateNormal)];
    sureBtn.titleLabel.font = KFontPingFangSCBold(15);
       [sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [whiteView addSubview:sureBtn];

       [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
              make.right.equalTo(whiteView.mas_right).mas_offset(-30);
            make.top.equalTo(whiteView.mas_top).mas_offset(123);
                                  make.width.mas_equalTo(50);
                                  make.height.mas_equalTo(20);
       }];
    
}
-(void)setContentText:(NSString *)contentText
{
    _contentText = contentText;
    self.contentLab.text = _contentText;
}
-(void)cancleBtnAction:(UIButton *)btn
{
    [self removeFromSuperview];
}
-(void)sureBtnAction:(UIButton *)btn
{
    if (self.sureBtnHandle) {
        self.sureBtnHandle();
    }
}
@end
